﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using bdnt_pets_system_Entity;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;

namespace bdnt_pets_system.Tools
{
    public static class DictInfoManager
    {
        /// <summary>
        /// 所有数据字典
        /// </summary>
        public static ObservableCollection<Tbl_DictInfo> AllDicts = new ObservableCollection<Tbl_DictInfo>();

        public static List<Tbl_DictInfo> CurrentDicts = new List<Tbl_DictInfo>();

        public static bool LoadDictsByPId(int objId)
        {
            var objs = AllDicts.Where(p => p.PId == objId).OrderBy(p => p.Sequence).ToList();
            if (objs.Count > 0)
            {
                CurrentDicts = objs;
                return true;
            }
            return false;
        }
         
        public static void AddToAllDicts(List<Tbl_DictInfo> cuDicts)
        {
            CurrentDicts = cuDicts.OrderBy(p => p.Sequence).ToList();
            foreach (var item in CurrentDicts)
            {
                AllDicts.Add(item);
            }
           
            var allList = AllDicts.Distinct().ToList();
            AllDicts.Clear();
            allList.ForEach(p => AllDicts.Add(p));
        }
         
    }
}
